import { auth } from '/@/utils/common'

export type OrderStatusEnumType = {
    toPay: string
    toShipped: string
    toReceive: string
    toEvaluate: string
    complete: string
    cancel: string
    applyCancel: string
}

export enum orderStatusEnum {
    toPay = '1',
    toShipped = '2',
    toReceive = '3',
    toEvaluate = '4',
    complete = '5',
    cancel = '6',
    applyCancel = '7',
}

export const getStatusType = (status: string | number) => {
    status = status.toString()
    switch (status) {
        case orderStatusEnum.toShipped:
        case orderStatusEnum.applyCancel:
            return 'warning'
        case orderStatusEnum.toReceive:
        case orderStatusEnum.toEvaluate:
        case orderStatusEnum.complete:
            return 'success'
        case orderStatusEnum.cancel:
            return 'danger'
        default:
            return 'info'
    }
}

export const showDeliveryButton = (row: TableRow) => {
    return row.status == orderStatusEnum.toShipped && auth({ name: '/admin/shop/order/order', subNodeName: '/admin/shop/order/delivery/delivery' })
}

export const showCancelButton = (row: TableRow) => {
    return row.status == orderStatusEnum.applyCancel && auth({ name: '/admin/shop/order/order', subNodeName: '/admin/shop/order/order/cancel' })
}

export const showCloseButton = (row: TableRow) => {
    if (parseFloat(row.refund_amount) > 0) return false
    if (row.status == orderStatusEnum.complete) return false
    if (row.status == orderStatusEnum.cancel) return false
    if (row.status == orderStatusEnum.applyCancel) return false

    return auth({ name: '/admin/shop/order/order', subNodeName: '/admin/shop/order/order/close' })
}

export const showExportButton = () => {
    return auth({ name: '/admin/shop/order/order', subNodeName: '/admin/shop/order/order/addExportTask' })
}
